package com.hand.springboot.repository.Impl;

import com.hand.springboot.entity.student;
import com.hand.springboot.repository.StudentRepository;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author xiongyilin
 * @Date 2019/8/8 19:50
 * @Version 1.0
 */
@Repository
public class StudentRepositoryImpl implements StudentRepository {
    public static Map<Long,student> studentMap;

    static {
        studentMap =new HashMap<>();
        studentMap.put(1L,new student(1L,"张三",22));
        studentMap.put(2L,new student(2L,"李四",23));
        studentMap.put(3L,new student(3L,"王五",24));
    }

    @Override
    public Collection<student> findAll() {
        return studentMap.values();
    }

    @Override
    public student findById(long id) {
        return studentMap.get(id);
    }

    @Override
    public void saveOrUpdate(student s) {
        studentMap.put(s.getId(),s);
    }

    @Override
    public void deleteById(long id) {
        studentMap.remove(id);
    }
}
